//
//  SubEnterpriseViewController.m
//  Utils
//
//  Created by enghou on 2018/4/18.
//  Copyright © 2018年 xyxorigation. All rights reserved.
//

#import "SubEnterpriseViewController.h"
#import "ManipulatorItemModel.h"
@interface SubEnterpriseViewController ()

@end

@implementation SubEnterpriseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"抄办单位";
    self.tableView.editing = YES;
    self.tableView.allowsMultipleSelection = YES;
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"确定" style:UIBarButtonItemStylePlain target:self action:@selector(sure)];
    self.navigationItem.rightBarButtonItem.tintColor = [UIColor whiteColor];
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

-(NSDictionary *)param{
    return @{@"issueStepId":self.stepId,@"page":[NSString stringWithFormat:@"%i",self.page],@"rows":@"10"};
}

-(void)sure{
    if ([self.theDelete respondsToSelector:@selector(fetchArray:)]) {
        NSArray *cells = [self.tableView indexPathsForSelectedRows];
        NSMutableArray *ret = [NSMutableArray array];
        for (NSIndexPath *path in cells) {
            NSInteger row = path.row;
            [ret addObject:self.source[row]];
        }
        [self.theDelete fetchArray:ret];
        [self.navigationController popViewControllerAnimated:YES];
    }else{
        [self alertSome:@"请选择抄办单位"];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"UITableViewCell"];
        cell.selectionStyle = UITableViewCellSelectionStyleBlue;
    }
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 44;
}

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
    ManipulatorItemModel *model = [self.source objectAtIndex:indexPath.row];
    cell.textLabel.text = model.name;
}

-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
    return UITableViewCellEditingStyleDelete | UITableViewCellEditingStyleInsert;
}

@end
